package com.scorpio.api.controller.order;

import java.util.List;

import com.scorpio.common.core.page.TableDataInfo;
import com.scorpio.order.vo.UpdateOrderMoneyVo;
import com.scorpio.order.vo.UpdateSendOutVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.scorpio.common.annotation.Log;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.AjaxResult;
import com.scorpio.common.enums.BusinessType;
import com.scorpio.order.domain.OrderEntity;
import com.scorpio.order.service.IOrderService;
import com.scorpio.common.utils.poi.ExcelUtil;
import org.springframework.validation.annotation.Validated;


/**
 * 订单Controller
 *
 * @author scorpio
 * @date 2022-01-11
 */
@RestController
@RequestMapping("/order/order")
public class OrderController extends BaseController {
    @Autowired
    private IOrderService service;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderEntity order) {
        startPage();
        List<OrderEntity> list = service.selectList(order);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderEntity order) {
        List<OrderEntity> list = service.selectList(order);
        ExcelUtil<OrderEntity> util = new ExcelUtil<>(OrderEntity.class);
        return util.exportExcel(list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(service.selectById(id));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "更新物流信息", businessType = BusinessType.UPDATE)
    @PostMapping("updateLogisticsInfo")
    public AjaxResult updateLogisticsInfo(@RequestBody @Validated UpdateSendOutVo vo) {
        return toAjax(service.updateLogisticsInfo(vo));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "更新发货状态", businessType = BusinessType.UPDATE)
    @PostMapping("updateSendOut")
    public AjaxResult updateSendOut(@RequestBody @Validated UpdateSendOutVo vo) {
        return toAjax(service.updateSendOut(vo));
    }

    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "修改支付价格", businessType = BusinessType.UPDATE)
    @PostMapping("updateOrderMoney")
    public AjaxResult updateOrderMoney(@RequestBody @Validated UpdateOrderMoneyVo vo) {
        return toAjax(service.updateOrderMoney(vo));
    }
}
